package com.sssd.utils;

import java.awt.*;
import java.util.List;

/**
 * @author sssd
 * @update 2023-02-05 21:58
 */
public class RobotUtil {
    public static Robot robot;

    static {
        try {
            robot = new Robot();
        } catch (AWTException e) {
            e.printStackTrace();
        }
    }

    /**
     * 按键按下弹起
     *
     * @param keys
     */
    public static void pressKeyToPopUp(List<Integer> keys) {
        keys.forEach(key -> {
            robot.keyPress(key);
        });
        keys.forEach(key -> {
            robot.keyRelease(key);
        });
    }

    /**
     * 按键按下指定时间弹起
     *
     * @param keys
     * @param time
     */
    public static void pressKeyToPopUp(List<Integer> keys, int time) {
        keys.forEach(key -> {
            robot.keyPress(key);
        });
        robot.delay(time);
        keys.forEach(key -> {
            robot.keyRelease(key);
        });
    }
}
